layui.use(['element', 'form', 'layer'], function () {
    var element = layui.element,
        form = layui.form,
        layer = layui.layer
        ;

    var config = {};
    var gfanConf = {};
    // 机锋相关参数表单赋值
    chrome.storage.sync.get('gfan', ({ gfan }) => {
        gfanConf = gfan;
        form.val("form-gfan-params", gfan.reply);
    });

    var setGfanReplyProperty = function setGfanReplyProperty(key, value){
        gfanConf.reply[key] = value;
        setGfan();
    };

    var setGfanReply = function (reply){
        gfanConf.reply = reply;
        setGfan();
    }

    var setGfan = function(){
        chrome.storage.sync.set({gfan:gfanConf}, () => layer.msg('设置成功'));
    }

    form.on('switch(isReplyAllPosting)', ({ elem }) => {
        setGfanReplyProperty('isReplyAllPosting', elem.checked);
    });

    // 机锋参数(gfanParams)设置表单提交
    form.on('submit(gfanParams)', function ({ elem, form, field }) {
        console.log(field);
        setGfanReply(field);
        return false;
    });
})